import pygame
from pygame.locals import *

class HealthBar(pygame.sprite.Sprite):
	def __init__(self, spritesheet):
		pygame.sprite.Sprite.__init__(self)
		
		self._image = spritesheet.get_image(Rect((448, 0), (128, 64)))
		self.image = pygame.surface.Surface((128, 64))
		self.rect = Rect((320 - 64, 0), (128, 64))
	
	def update(self, health):
		font = pygame.font.Font(None, 24)
		text = font.render("%s" % int(health), 1, (0, 0, 0))
		textpos = (58, 24)
		self.image.blit(self._image, (0, 0))
		self.image.blit(text, textpos)
		self.image.set_colorkey(self.image.get_at((0, 0)), RLEACCEL)